<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<div class="modal fade" id="modal-modify" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="myModalLabel1">
                    生产厂分配
                </h4>
            </div>
            <form id="sheetForm" class="form-horizontal">
                <div class="box-body">
                    <table id="bootstrap-table1"></table>
                </div>
                <input type="hidden" id="workShop">
            </form>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" id="btn-maintain1" onclick="submitCJ()">
                    提交
                </button>
            </div>
        </div>
    </div>
</div>


<section class="content-header">
    <h1>生产运营部图纸签收</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">项目编号</label>
                                    <input id="query-proCode" type="text" name="proCode" class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-malType">类型</label>
                                    <select id="query-malType" class="form-control" name="special">
                                        <option value="" selected>请选择</option>
                                        <option th:each="type : ${special}" th:value="${type.name}"
                                                th:text="${type.name}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-part">部分</label>
                                    <input id="query-part" type="text" name="part" class="form-control"
                                           placeholder="请输入部分">
                                </div>

                                <div class="form-group">
                                    <label for="query-designer">设计者</label>
                                    <input id="query-designer" type="text" name="designer" class="form-control"
                                           placeholder="请输入设计者">
                                </div>

                                <div class="form-group">
                                    <label for="query-productionSignStatus">生产签收状态</label>
                                    <select id="query-productionSignStatus" class="form-control" name="productionSignStatus">
                                        <option value="" selected>请选择</option>
                                        <option value="0">未签收</option>
                                        <option value="1">已签收</option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table,table2;


    /** 就绪函数初始化*/
    $(function () {
        /** 加载列表 */
        table = js.table.init({
            url: ctx + "tecdrawsign/list",
            showExport: true,
            uniqueId: 'id',
            columns: [
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "项目编号", field: 'proCode'},
                {title: "项目名称", field: 'proName'},
                {title: "类型", field: 'special'},
                {title: "部分", field: 'part'},
                {title: "设计者", field: 'designer'},
                {title: "图纸<br>页数", field: 'drawPages'},
                {title: "制作件<br>清单<br>页数", field: 'makePages'},
                {title: "备注", field: 'remark'},
                {title: "设计提报时间", field: 'designTime'},
                {title: "档案签收时间", field: 'fileSignTime'},
                {title: "生产签收时间", field: 'productionSignTime'},
                {
                    title: "操作",
                    formatter: function (value, row) {

                        let actions = [];
                        if(row.productionSignStatus == 1 && row.distribution==0 && hasP("data:drawing:allot")){
                            actions.push('<a class="btn btn-success btn-xs" onclick="workShop(' + row.id + ')">车间分配</a> ');
                        }else if(row.productionSignStatus == 0 && hasP("data:drawing:sign")){
                            actions.push('<a class="btn btn-warning btn-xs" onclick="prodSign(' + row.id + ')">签收</a> ');
                        }
                        if(row.distribution==1){
                            actions.push('<a class="btn btn-info btn-xs" onclick="prodSelect(' + row.id + ')">查看</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        });

        /** 厂级加载列表 */
        table2 = js.table.init({
            url: ctx + "tecdrawsign/workshop",
            showExport: false,
            id:"bootstrap-table1",
            uniqueId: 'id',
            pagination: false,
            columns: [
                {
                    checkbox: true,
                    formatter: function (value, row) {
                        if (value) {
                            return {disabled: false}
                        }
                    }
                },
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "生产厂", field: 'name'},
            ]
        });

    });

    /** 生产厂模态框*/
    function workShop(id){
        $("#workShop").val(id)
        js.modal.open("modal-modify");

    }
/** 生产运营部分配生产厂*/
    function submitCJ(){
        debugger
        let lssueId = $("#workShop").val()
        let arr = js.table.selectRows("bootstrap-table1");
        if (arr.length < 1) {
            js.modal.alert("请选择要分配的工厂");
            return;
        }
        js.post({
            url: ctx + "tecdrawsign/submitCJ",
            async: false,
            data:{
                works:JSON.stringify(arr),
                lssueId:lssueId,
                changeType:1
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table)
                    js.modal.hide("modal-modify");
                    js.table.refresh(table2)

                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }

    /** 生产运营部签收*/
    function prodSign(id){
        js.post({
            url: ctx + "tecdrawsign/prodSign",
            async: false,
            data:{
                id:id,
                type:1
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table)
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });

    }

    /** 生产运营部查看*/
    function prodSelect(id){
        location.href = ctx + "tecdrawsign/tt?id="+id;
    }

</script>
</body>
</html>
